package com.zhentao.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 规则执行状态枚举
 * @author zhentao
 * @date 2024-12-19
 */
@Getter
@AllArgsConstructor
public enum RuleExecuteStatusEnum {
    
    /**
     * 执行成功
     */
    SUCCESS("SUCCESS", "执行成功", "规则执行成功并返回结果"),
    
    /**
     * 执行失败
     */
    FAILED("FAILED", "执行失败", "规则执行失败，但程序正常运行"),
    
    /**
     * 执行异常
     */
    ERROR("ERROR", "执行异常", "规则执行过程中发生异常"),
    
    /**
     * 规则不存在
     */
    NOT_FOUND("NOT_FOUND", "规则不存在", "指定的规则不存在"),
    
    /**
     * 规则已禁用
     */
    DISABLED("DISABLED", "规则已禁用", "规则处于禁用状态"),
    
    /**
     * 参数校验失败
     */
    PARAM_ERROR("PARAM_ERROR", "参数校验失败", "输入参数不符合规则要求"),
    
    /**
     * 超时
     */
    TIMEOUT("TIMEOUT", "执行超时", "规则执行超过最大允许时间"),
    
    /**
     * 缓存命中
     */
    CACHE_HIT("CACHE_HIT", "缓存命中", "从缓存中获取结果");
    
    private final String code;
    private final String name;
    private final String description;
    
    /**
     * 根据代码获取枚举
     */
    public static RuleExecuteStatusEnum getByCode(String code) {
        for (RuleExecuteStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
    
    /**
     * 是否为成功状态
     */
    public boolean isSuccess() {
        return this == SUCCESS || this == CACHE_HIT;
    }
    
    /**
     * 是否为失败状态
     */
    public boolean isFailed() {
        return this == FAILED || this == ERROR || this == NOT_FOUND || 
               this == DISABLED || this == PARAM_ERROR || this == TIMEOUT;
    }
}

